/*-------------------------------------------------------------------------
 - Copyright (c) 2024-2025 [XD-AMCC TEAM]
 - [XD-AMCC] is licensed under Mulan PSL v2.
 - You can use this software according to the terms and conditions of the Mulan PSL v2.
 - You may obtain a copy of Mulan PSL v2 at:
 -          http://license.coscl.org.cn/MulanPSL2
 - THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES
 - OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
 - TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
 - See the Mulan PSL v2 for more details.
 ------------------------------------------------------------------------*/


/**
 * @file
 * @brief  Interface for AMCC configuration.
 *
 * NOTICE:::::
 *    This file does not need include-guard,
 *    and ONLY \#included by "amcc_config.h".
 *
 * @author  WXQ#XDU
 * @date    2024.11
 */

#include <stdbool.h>
#include <stdio.h>

AMCC_DECL_BEGIN

/// Get my name, version,  build date
extern const char * amcc_version_descript();

/// Get my build date and compiler
extern const char * amcc_build_info();

/// Get my organization
extern const char * amcc_organization();

/**
 * @brief Prepare basic kernel data of "configuration" module.
 * @param appName  name of application, NULL or empty string is acceptable
 * @note This function MUST be called before
 *       "amcc_bootup()",  "amcc_set*()".
 */
extern void amcc_boot0(const char * appName);


/**
 * @brief Let all modules initialize their internal data before it can work.
 * @note This function MUST be called AFTER call "amcc_set*()".
 */
extern int  amcc_bootup();

/**
 * @brief Let all modules clean their internal data to stop work.
 */
extern void amcc_shutdown(void);


//--------------------------------------------------------------------
//      Setter of AMCC-Configuration
//
// All setter MUST be called BEFORE call amcc_bootup()
//--------------------------------------------------------------------


/// Set the directory in where all output files are saved
extern void amcc_set_outputDir(const char * output_dir);

/// Set default log level.  Default is LOG_INFO.
extern void amcc_set_logLevel(int defaultLogLevel);

/// Set whether the information of AMCC source file is logged.
// Default is false.
extern void amcc_set_logSource(bool  isLogSource);

/// Set whether the timestamp is logged.
// Default is false.
extern void amcc_set_logTime(bool  isLogTime);

/// Set whether log the call-stack of Recursive-Descent-Functions in parser.
// Default is false.
extern bool amcc_set_logParserStack(bool yesORno);

/// Set and get attributes about input files.
extern void amcc_set_inputFilePath(const char * inFile);

/// Set the file to save all error information. Default is 'stderr'
extern void amcc_set_errorFile(FILE * fp);

/// Set whether report error if no main() function
extern void amcc_set_shouldExistMain(bool onOff);

/// Set the prefix of temporary variable name
void amcc_set_tempvar_prefix(const char* prefix);


//--------------------------------------------------------------------
//      Getter of AMCC-Configuration
//--------------------------------------------------------------------

/// get app-name which was set by amcc_boot0()
extern const char * amcc_get_appname();

/// get the directory in where all output files are saved
extern const char * amcc_get_outputDir();

extern int amcc_get_logLevel();        //!< Get default log level
extern const char* amcc_get_logFile(); //!< get path of log file
extern bool amcc_is_logSource();       //!< log source file info ?
extern bool amcc_is_logTime();         //!< log time-stamp ?

/// Whether log the RDF call stack of parser, default is false
extern bool amcc_is_logParerStack();

/// Get the path of input files
extern const char * amcc_get_inputFilePath();

/// Get the file to save all error information
extern FILE * amcc_get_errorFile();

/// Get the file-path to save all tokens
extern const char* amcc_get_tokenFilePath();

/// Get the file-path to save all parse-trees
extern const char* amcc_get_treeFilePath();

/// Get the file-path to save symbol-entries
extern const char* amcc_get_symbolFilePath();

/// Get the file-path to save all IR-codes
extern const char* amcc_get_irCodeFilePath();

/// Whether report error if no main() function
extern bool amcc_shouldExistMain() ;

/// Get the prefix of temporary variable name
const char * amcc_get_tempvar_prefix();


/// Get the offset of a field 'member' in the struct 'type'
#define AMCC_OFFSETOF(type, member)         (size_t)(&(((type *)0)->member))

/// Get the address of a field by its offset in a variable of struct 'type'
#define AMCC_ADDRESS(type, varPtr, offset)  (*(type*)((size_t)(varPtr) + (offset)))



AMCC_DECL_END
